package view.WelcomePanels.SubPanels.FormPanels;

import domain.WelcomeController;
import dto.RegisterDTO;
import dto.WelcomeDTO;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

/**
 *
 * @author Joachim
 */
public class RegisterFormPanel extends AbstractFormPanel {
    
    private JPasswordField pswPassword, pswRepeatPassword;
    
    public RegisterFormPanel(WelcomeDTO dto, WelcomeController controller) {
        super(dto, controller);
    }
    
    @Override
    protected void addSpecificComponents() {
        c.insets = new Insets(10,0,0,0);
        {
            JLabel lblPassword = new JLabel("Password: ");
            c.gridx = 0;
            c.gridy = 1;
            c.weightx = 0.1;
            c.fill = GridBagConstraints.BOTH;
            this.add(lblPassword,c);
        }
        {
            pswPassword = new JPasswordField(15);
            pswPassword.setBorder(BorderFactory.createLineBorder(new Color(28,28,28,100)));
            pswPassword.getDocument().addDocumentListener(new DocumentListener() {
                public void changedUpdate(DocumentEvent e) {fillDTO();}
                public void removeUpdate(DocumentEvent e) {fillDTO();}
                public void insertUpdate(DocumentEvent e) {fillDTO();}
                public void fillDTO() {
                   ((RegisterDTO)dto).setPassword(pswPassword.getText());
                }
            });
            c.gridx = 1;
            c.gridy = 1;
            c.weightx = 1.0;
            c.fill = GridBagConstraints.BOTH;
            this.add(pswPassword,c);
        }
        c.insets = new Insets(10,0,0,0);
        {
            JLabel lblRepeatPassword = new JLabel("Repeat password: ");
            c.gridx = 0;
            c.gridy = 2;
            c.weightx = 0.1;
            c.fill = GridBagConstraints.BOTH;
            this.add(lblRepeatPassword,c);
        }
        {
            pswRepeatPassword = new JPasswordField(15);
            pswRepeatPassword.setBorder(BorderFactory.createLineBorder(new Color(28,28,28,100)));
            pswRepeatPassword.getDocument().addDocumentListener(new DocumentListener() {
                public void changedUpdate(DocumentEvent e) {fillDTO();}
                public void removeUpdate(DocumentEvent e) {fillDTO();}
                public void insertUpdate(DocumentEvent e) {fillDTO();}
                public void fillDTO() {
                   ((RegisterDTO)dto).setRepeatPassword(pswRepeatPassword.getText());
                }
            });
            c.gridx = 1;
            c.gridy = 2;
            c.weightx = 1.0;
            c.fill = GridBagConstraints.BOTH;
            this.add(pswRepeatPassword,c);
        }
    }
    
}
